package com.waves.task.service.impl;

import java.util.concurrent.*;

class MyTask implements Runnable {
    private String id;

    public MyTask(String id) {
        this.id = id;
    }

    public void run() {
        String name = Thread.currentThread().getName();
        System.out.println(name+id);
    }
}

public class RejectPolicy {
    public static void main(String[] args) {
        CompletableFuture.runAsync(()-> System.out.println(1))
                .thenRun(()-> System.out.println(2));

        ExecutorService es = new ThreadPoolExecutor(2, 2, 0L, TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
        MyTask t1 = new MyTask("我的id:1");
        MyTask t2 = new MyTask("我的id:2");
        MyTask t3 = new MyTask("我的id:3");
        MyTask t4 = new MyTask("我的id:4");
        MyTask t5 = new MyTask("我的id:5");
        MyTask t6 = new MyTask("我的id:6");
        MyTask t7 = new MyTask("我的id:7");

        es.execute(t1);
        es.execute(t2);
        es.execute(t3);
        es.execute(t4);
        es.execute(t5);
        es.execute(t6);
        es.execute(t7);
    }
}
